﻿using ProjectCloth.Entity;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ProjectCloth.FrmUI
{
    public partial class RoleFrm : Form
    {
        private ClothContext db = new ClothContext();
        public RoleFrm()
        {
            InitializeComponent();
        }

        private void saveBtn_Click(object sender, EventArgs e)
        {
           var count= db.Roles.Where(o =>  o.Name == nameTxt.Text).Count();
            if (count > 0)
            {
                MessageBox.Show("该角色已经存在！");
                return;
            }
            var role = new Role()
            {
                Name = nameTxt.Text,
               
            };
            db.Roles.Add(role);
            var result = db.SaveChanges();
            if (result > 0)
            {
                MessageBox.Show("保存成功！");
            }
        }
    }
}
